home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / Gfx4PCQ.lha / WindowLib / Examples / SpriteDemo2 / SpriteDemo2.p < prev    next >
Encoding:
Text File  |  1997-07-19  |  5.3 KB  |  140 lines

  1. Program SpriteDemo;
  2. {Another sample program for sprites, © 1997 THOR-Software inc.
  3.  
  4.  We present bobs this time. They aren't real hardware sprites, but
  5.  animated figures drawn by the blitter.
  6.  They can be as wide as you wish, but share the colors of the screen
  7.  and are usually more flickering.
  8.  
  9.  We show as well how to read the joystick.
  10. }
  11.  
  12. Procedure WaitTOF;
  13. External;
  14. {$I "include:utils/windowlib.i"}
  15. {$I "include:utils/stringlib.i"}
  16.   
  17. PROCEDURE Demo;
  18.  
  19. TYPE    
  20.         SpriteArray     =       Array[0..10] of String;    {contains the shapes}
  21. CONST
  22.     {Definition of the sprite shapes... Just some nonsense, I'm not an
  23.      artist!}
  24.  
  25.         Shape1 : SpriteArray    =       (
  26.                 "                ..............                 ",
  27.                 "        ..........++++++++++............       ",
  28.                 "    ........+++++++++++++++++++++++++.......   ",
  29.                 " ......+++++++         *            +++++..... ",
  30.                 "...++++++             ***             ++++++...",
  31.                 "...+++++*******************************+++++...",
  32.                 "...++++++             ***             ++++++...",
  33.                 " ......+++++++         *           ++++++..... ",
  34.                 "    ........+++++++++++++++++++++++++.......   ",
  35.                 "        ..........++++++++++............       ",
  36.                 "                ..............                 ");
  37.  
  38.         Shape2 : SpriteArray    =       (
  39.                 "                ..............                 ",
  40.                 "        ..........++++++++++............       ",
  41.                 "    ........+++++++++++++++++++++++++.......   ",
  42.                 " ......+++++++******        ********+++++..... ",
  43.                 "...++++++           *** ****          ++++++...",
  44.                 "...+++++              ***              +++++...",
  45.                 "...++++++           *** ****          ++++++...",
  46.                 " ......+++++++******        *******++++++..... ",
  47.                 "    ........+++++++++++++++++++++++++.......   ",
  48.                 "        ..........++++++++++............       ",
  49.                 "                ..............                 ");
  50.  
  51.         Shape3 : SpriteArray    =       (
  52.                 "                ..............                 ",
  53.                 "        ..........++++++++++............       ",
  54.                 "    ........+++++++++++++++++++++++++.......   ",
  55.                 " ......+++++++        ****          +++++..... ",
  56.                 "...++++++           **    **          ++++++...",
  57.                 "...+++++           *        *          +++++...",
  58.                 "...++++++           **    **          ++++++...",
  59.                 " ......+++++++        ****         ++++++..... ",
  60.                 "    ........+++++++++++++++++++++++++.......   ",
  61.                 "        ..........++++++++++............       ",
  62.                 "                ..............                 ");
  63.  
  64.  
  65.  
  66. VAR
  67.         s       :       ScreenPtr;
  68.         w       :       WindowPtr;    {holds window and screen}
  69.         sp1     :       SpritePtr;
  70.         sp2     :       SpritePtr;
  71.         sp3     :       SpritePtr;    {holds sprites}
  72.         xm,ym   :       Short;
  73.     x,y    :    Short;        {mouse and joystick position}
  74.     mask    :    Integer;    {tmp to store the collision mask}
  75.                 
  76. BEGIN
  77.     {open screen & window}
  78.         s:=OpenAScreen(0,0,640,256,2,MON_HIRES or MON_NTSC,"Testscreen");
  79.         IF s<>NIL THEN BEGIN
  80.                 
  81.                 w:=OpenScreenWindow(s,0,0,640,256,2+4+8,"A Test");
  82.                 
  83.                 IF w<>NIL THEN BEGIN
  84.  
  85.             {create the sprites, this time as "bobs", not as true hardware sprites}
  86.                         sp1:=OpenSprite(w,@Shape1[0],11,SPRITE_SAVEBACK or SPRITE_OVERLAY);
  87.                         sp2:=OpenSprite(w,@Shape2[0],11,SPRITE_SAVEBACK or SPRITE_OVERLAY);
  88.                         sp3:=OpenSprite(w,@Shape3[0],11,SPRITE_SAVEBACK or SPRITE_OVERLAY);
  89.  
  90.  
  91.             {define priorities. This works only for bobs!
  92.              Note that the order of this definition is IMPORTANT!
  93.              See the guide for more!}
  94.             InFrontOf(sp1,sp2);
  95.             InFrontOf(sp2,sp3);
  96.  
  97.             {Setup memask and hitmask of the sprites. Collect
  98.              collisions with the first sprite with all others.
  99.              Read the guide for more information on this.}
  100.  
  101.             SetCollisionMasks(sp1,2,4+8);
  102.             SetCollisionMasks(sp2,4,2);
  103.             SetCollisionMasks(sp3,8,2);
  104.  
  105.             {setup the position}
  106.             x:=100;
  107.             y:=100;
  108.                         REPEAT
  109.                                 Mouse(w,xm,ym);    {read the mouse}
  110.  
  111.                                 PlaceSprite(sp1,x SHL 16,y SHL 16);
  112.                                 PlaceSprite(sp2,xm SHL 16,120 SHL 16);
  113.                                 PlaceSprite(sp3,200 SHL 16,ym SHL 16);
  114.                 {place the sprites}
  115.     
  116.                 AnimateSprites(w);    {and show them}
  117.  
  118.                 mask:=ReadCollisionMask(sp1,TRUE);    {read the collision mask, clear it and print it}
  119.                 writeln(mask);
  120.  
  121.                 WaitForStick(1);            {wait until something happens with the joystick}
  122.                 {and update the positions}
  123.                 If StickUp(1) AND (y>0) THEN y:=y-1;
  124.                 If StickDown(1) AND (y<200) THEN y:=y+1;
  125.                 If StickLeft(1) AND (x>0) THEN x:=x-1;
  126.                 If StickRight(1) AND (x<640) then x:=x+1;
  127.             UNTIL Strig(1);
  128.         
  129.                         CloseAWindow(w);
  130.                 END;
  131.                 CloseAScreen(s);
  132.         END;
  133. END;
  134.  
  135. BEGIN
  136.         InitGraphics;
  137.         Demo;
  138.         ExitGraphics;
  139. END.
  140.